<?php

use yii\db\Migration;

/**
 * Handles the creation of table `coupon`.
 */
class m180308_073830_create_coupon_table extends Migration
{
    /**
     * CREATE TABLE `coupon` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `code` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '券码',
    `origin_num` int(11) NOT NULL DEFAULT '1' COMMENT '优惠券数量',
    `use_num` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '领取数',
    `catalog` int(11) NOT NULL COMMENT '优惠券分类',
    `created_at` int(11) NOT NULL COMMENT '创建时间',
    `updated_at` int(11) NOT NULL COMMENT '更新时间',
    `expire_at` int(11) NOT NULL COMMENT '过期时间',
    `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '名称',
    `consumption_amount` decimal(8,2) DEFAULT NULL COMMENT '消费金额',
    `discount_amount` decimal(8,2) DEFAULT NULL COMMENT '折扣金额',
    `password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '密码',
    `status` smallint(6) NOT NULL COMMENT '状态',
    PRIMARY KEY (`id`),
    UNIQUE KEY `coupon_code_unique` (`code`)
    ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
     */
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%coupon}}', [
            'id' => $this->primaryKey(),
            'origin_id'=>$this->integer(11)->comment("原始ID"),
            'code' => $this->string(30)->unique()->comment("优惠券号"),
            'origin_num' => $this->integer(10)->comment("初始值"),
            'use_num' => $this->integer(10)->comment("领取数"),
            'catalog' => $this->smallInteger(3)->comment("分类"),
            'catalog_mark_id'=>$this->string(255)->comment("分类标识"),
            'created_at' => $this->integer(11)->comment("创建时间"),
            'updated_at' => $this->integer(11)->comment("更新时间"),
            'expire_at' => $this->integer(11)->comment("过期时间"),
            'name'=>$this->string(255)->comment("名称"),
            'consumption_amount'=>$this->decimal(8,2)->comment("消费金额"),
            'discount_amount'=>$this->decimal(8,2)->comment("折扣金额"),
            'password'=>$this->string(50)->comment("密码"),
            'status'=>$this->smallInteger(3)->comment("状态"),

        ], $tableOptions);
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function down()
    {
        $this->dropTable('{{%coupon}}');
        return true;
    }
}
